<template>
    <el-select :value="value" clearable :placeholder="placeholder" style="width:100%" @input="sendChange"
        :disabled="disabled">
        <el-option v-for="item in Options" :key="item.userId" :label="item.username" :value="item.userId">
        </el-option>
    </el-select>
</template>
<script>
    import * as userService from '@/api/upms/user'
    export default {
        props: {
            value: {
                type: String,
                default: ""
            },
            pkGroup: {
                type: [String, Number],
                default: ""
            },
            pkOrg: {
                type: [String, Number],
                default: ""
            },
            pkDept: {
                type: [String, Number],
                default: ""
            },
            userType: {
                type: [String, Number],
                default: ""
            },
            username: {
                type: [String, Number],
                default: ""
            },
            placeholder: {
                type: String,
                default: "请选择用户"
            },
            disabled: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                Options: [],
                currentValue: ''
            }
        },
        watch: {
            pkGroup(val) {
                this.getDict()
            },
            pkOrg(val) {
                this.getDict()
            },
            pkDept(val) {
                this.getDict()
            },
            username(val) {
                this.getDict()
            },
            userType(val) {
                this.getDict()
            }
        },
        mounted() {
            this.getDict()
        },
        methods: {
            getDict() {
                let query = {
                    userType: this.userType || "",
                    pkGroup: this.pkGroup || "",
                    pkOrg: this.pkOrg || "",
                    pkDept: this.pkDept || "",
                    username: this.username || ""
                }
                userService.getuserlist(query).then(data => {
                    this.Options = data
                    this.sendChange(this.value)
                })
            },
            sendChange(currentValue) {
                this.currentValue= currentValue
                this.$emit("input", currentValue);
                this.$emit("getOptionDetail",this.Options.find(i => i.userId == this.currentValue))
            }
        }
    }
</script>